package com.chapp.util;

import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.widget.Toast;

import com.chapp.ui.Main;

public class Utils {

	public static void messageToast(Context context, String msg) {
		Toast.makeText(context, msg, 8000).show();
	}

	public static void goHome(Context context) {
		final Intent intent = new Intent(context, Main.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		context.startActivity(intent);
	}

	public static void goMap(Context context, String lati, String longi) {
		final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo: 0,0?q="
				+ lati + ", " + longi));
		context.startActivity(i);
	}

	public static boolean isNetworkConnected(Context context) {
		ConnectivityManager connec = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		NetworkInfo ni = connec.getActiveNetworkInfo();

		return ni.isConnected();
	}

	public static boolean isConnectingNetwork(Context context) {
		ConnectivityManager connec = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		NetworkInfo ni = connec.getActiveNetworkInfo();
		if (ni != null) {
			return ni.isConnectedOrConnecting();
		}

		return false;
	}

	public static Location getLocation(Context context) {
		Location location = null;
		LocationManager locationM = (LocationManager) context
				.getSystemService(Context.LOCATION_SERVICE);

		location = locationM
				.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
		
		

		return location;
	}
}
